<?php
define('DB_NAME', 'program');
define('DB_HOST', 'localhost');

define('DB_USER', 'root');
define('DB_PASS', '');

function db_connect() {
	try {
		$db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS);
	} catch (PDOException $e) {
		redirectOnError(999);
	}
	return $db;
}

//returns the number of the rows returned by the last SELECT .... LIMIT, if it hadn't been LIMIT
//SQL_CALC_FOUND_ROWS must be used in that SELECT for this to work
function queryGetSelectFoundRows($db){
  $query = "SELECT FOUND_ROWS() AS found_rows";
  if (!($res = $db->query($query))) return null;
  $row = $res->fetch_assoc();
  return (int) $row['found_rows'];
}

?>